package ui.faces
{
	import events.GestureEvent;
	
	import global.Managers;
	
	import ui.components.Button;
	import ui.panels.PanelType;
	
	/**
	 *
	 * 主界面
	 * @author Raykid
	 * 
	 */	
	public class MainFace extends AbstractFace
	{
		private var _btnOrdered					: Button;
		private var _btnMenu					: Button;
		private var _btnChangeLanguage			: Button;
		
		public function MainFace()
		{
			super();
		}
		override protected function createBG():void {
			super.createBG();
			_bg.addChild(Managers.resourceManager.getBitmap("faces/mainBG.jpg"));
		}
		override protected function createView():void {
			super.createView();
			
			_btnOrdered = new Button(0, _languageManager.getLanguageText("ordered"), 150, 40, "", function(event:GestureEvent):void {
				Managers.panelManager.open(PanelType.ORDERED_DISH);
			});
			_btnOrdered.x = 850;
			_btnOrdered.y = 600;
			addChild(_btnOrdered);
			_btnOrdered.addListener(this);
			
			_btnChangeLanguage = new Button(1, _languageManager.getLanguageText("translate"), 150, 40, "", function(event:GestureEvent):void {
				_languageManager.currentLanguage = 3 - _languageManager.currentLanguage;
			});
			_btnChangeLanguage.x = 850;
			_btnChangeLanguage.y = 660;
			addChild(_btnChangeLanguage);
			_btnChangeLanguage.addListener(this);
			
			_btnMenu = new Button(2, _languageManager.getLanguageText("menu"), 150, 40, "", function(event:GestureEvent):void {
				Managers.faceManager.switchTo(Managers.faceManager.diningFace);
			});
			_btnMenu.x = 850;
			_btnMenu.y = 720;
			addChild(_btnMenu);
			_btnMenu.addListener(this);
		}
		
		/**
		 *
		 * 切换语言 
		 * @param toLanguage 切换到的语言
		 * 
		 */
		override public function switchLanguage(toLanguage:int):void
		{
			super.switchLanguage(toLanguage);
			
			if(toLanguage == _currentLanguage) return;
			_currentLanguage = toLanguage;
			
			_btnOrdered.text = _languageManager.getLanguageText("ordered");
			_btnMenu.text = _languageManager.getLanguageText("menu");
			_btnChangeLanguage.text = _languageManager.getLanguageText("translate");
		}
	}
}